<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Form</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .login-container h2 {
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
        }
        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .form-group button {
            width: 100%;
            padding: 10px;
            border: none;
            background-color: #5cb85c;
            color: white;
            border-radius: 5px;
            cursor: pointer;
        }
        .form-group button:hover {
            background-color: #4cae4c;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2>账号密码登录</h2>
    <form action="/login1?target=/user" method="post">
        <div class="form-group">
            <label for="uname">Username:</label>
            <input type="text" id="uname" name="uname" required>
        </div>
        <div class="form-group">
            <label for="pwd">Password:</label>
<!--            <input type="pwd" id="pwd" name="pwd" value="123" required>-->
            <input type="text" id="pwd" name="pwd" value="123" required>
        </div>
        <div class="form-group">
            <img src="vc.jpg">
            <input type="text" id="vcode" name="vcode" required>
        </div>
        <div class="form-group">
            <button type="submit">Login</button>
        </div>
    </form>
</div>
<div class="login-container">
    <h2>手机号登陆</h2>
    <form action="/login_sms?target=/user" method="post">
        <div class="form-group">
            <label for="phone">手机号:</label>
            <input type="text" id="phone" name="phone_smsAuthenticationFilter" value=""  required>
        </div>
        <div class="form-group">
            <label for="code">验证码:</label>
            <input type="text" id="code" name="code_smsAuthenticationFilter" value="" required>
            <button onclick="sendSms()">发送短信</button>
        </div>
        <div class="form-group">
            <button type="submit">Login</button>
        </div>
    </form>
</div>
<script>
    // 发送验证码
    function sendSms() {
        const phone = document.getElementById('phone').value;
        if (!phone) {
            alert('请输入手机号');
            return;
        }
        // 发送请求到后端API获取验证码
        fetch('/sendSms', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ phone }),
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('验证码已发送');
                } else {
                    alert('发送失败，请重试');
                }
            })
            .catch((error) => {
                console.error('Error:', error);
            });
    }

    // 登录
    function login() {
        const phone = document.getElementById('phone').value;
        const code = document.getElementById('code').value;
        if (!phone || !code) {
            alert('手机号和验证码不能为空');
            return;
        }
        // 发送请求到后端API验证验证码
        fetch('/sendSms', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ phone, code }),
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('登录成功');
                    // 进行后续的登录成功处理，比如页面跳转
                } else {
                    alert('验证码错误或已过期');
                }
            })
            .catch((error) => {
                console.error('Error:', error);
            });
    }
</script>
</body>
</html>